home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / OPENSPAC.ASM < prev    next >
Assembly Source File  |  1994-04-29  |  1KB  |  71 lines

  1. ; OPENSPAC.ASM for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. include    model.inc
  5.  
  6. ;
  7. ; This subroutine inserts spaces into the file buffer.  On entry, EAX
  8. ; contains the number of spaces to be inserted.  On return, CF = 1 if
  9. ; there was not enough space in the file buffer.
  10. ;
  11. ; assumes FS = file buffer selector
  12. public    open_space
  13. extrn    add_push:near
  14. extrn    working:near
  15. extrn    memcopy:near
  16.  
  17. include    dataseg.inc
  18. extrn    filesiz:dword, buffersiz:dword
  19. extrn    cursor:dword, dirty_bits:byte
  20. @curseg    ends
  21.  
  22. include    codeseg.inc
  23. open_space    proc    near
  24.     mov    ecx,filesiz    ; last character in file
  25.     add    ecx,eax
  26.     cmp    ecx,buffersiz
  27.     ja    short no_room
  28.     mov    filesiz,ecx
  29.     mov    esi,cursor    ; source
  30.     sub    ecx,eax
  31.     sub    ecx,esi        ; ECX = bytes to move
  32.     mov    edi,esi
  33.     add    edi,eax        ; EDI = destination
  34.  
  35.     push    ds
  36.     mov    bx,fs
  37.     mov    es,bx
  38.     mov    ds,bx
  39.     call    memcopy        ; memcopy uses DWORD-aligned DWORD copy
  40.                 ; for speed
  41.     pop    ds
  42.  
  43. ; mark file changed
  44.     or    dirty_bits,11000000b
  45.     call    add_push    ; adjust push offset if nessesary
  46.     ret
  47.  
  48. ;
  49. ; ECX = minimum bytes required
  50. ;
  51. no_room:
  52.     call    working
  53.     pushad
  54.     add    ecx,1023    ; round up to nearest k
  55.     and    ecx,(not 1023)    ; bytes requested
  56.     mov    bx,fs        ; selector
  57.     push    ecx
  58.     sys    ResMem32
  59.     pop    ecx
  60.     jc    short no0
  61.     mov    buffersiz,ecx    ; new buffer size
  62. no0:
  63.     popad
  64.     jnc    open_space
  65.     ret
  66.  
  67. open_space    endp
  68.  
  69. @curseg    ends
  70.     end
  71.